package cc.mrbird.febs.system.service.impl;

import cc.mrbird.febs.system.domain.TResidentHouse;
import cc.mrbird.febs.system.dao.TResidentHouseMapper;
import cc.mrbird.febs.system.manager.TempInfoManager;
import cc.mrbird.febs.system.service.ITResidentHouseService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author dtwei
 */
@Service
public class TResidentHouseServiceImpl extends ServiceImpl<TResidentHouseMapper, TResidentHouse> implements ITResidentHouseService {

    @Resource
    private TempInfoManager tempInfoManager;

    @Override
    public void deleteByHouseIds(List<String> houseIds) {
        LambdaQueryWrapper<TResidentHouse> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(TResidentHouse::getHouseId, houseIds);
        this.baseMapper.delete(queryWrapper);
    }

    @Override
    public void deleteByRsIds(List<String> rsIds) {
        LambdaQueryWrapper<TResidentHouse> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(TResidentHouse::getRsId, rsIds);
        this.baseMapper.delete(queryWrapper);
    }

    @Override
    public List<TResidentHouse> findAllHouseOwner() {
        LambdaQueryWrapper<TResidentHouse> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TResidentHouse::getRelation, "户主");
        List<TResidentHouse> retData = this.baseMapper.selectList(queryWrapper);

        try {
            tempInfoManager.loadAllHouseOwnerRedisCache(retData);
        } catch (Exception e) {
            log.error("redis error：", e);
        }

        return retData;
    }
}
